//
//  ECData_Json.m
//  Edu_iOS2018
//
//  Created by yanyan on 2018/1/20.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECData_Json.h"

@implementation ECData_Json
+(BOOL)successForRequestJson:(id)json
{
    if ([[json valueForKey:@"code"] integerValue] == 200) {
        //
        return YES;
    }
    return NO;
}
+ (BOOL)tokenFailureForRequestError:(NSError *)error
{
    NSHTTPURLResponse *response = error.userInfo[AFNetworkingOperationFailingURLResponseErrorKey];
    NSInteger statusCode = response.statusCode;
    //  token  失效。
    if (response.statusCode == 401) {
        return YES;
    }
    return NO;
}


/**
 返回错误提示码(预防根据错误码进行其他页面操作)
 @return 返回错误码 直接屏幕提示错误信息
 */
+(NSString *)requestErrorTipWith:(NSError *)error{
    NSData *errorData = error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
    if (errorData == nil) {
        [MBProgressHUD showTipMessageInWindow:@"网络超时"];
        return @"101";
    }
    NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: errorData options:kNilOptions error:nil];
    if ([[[serializedData objectForKey:@"code"]stringValue] isEqualToString:@"401"]) {
        [MBProgressHUD showTipMessageInWindow:kAlertTipOfTokenFailure];
        return @"401";
    }else{
        //[MBProgressHUD showTipMessageInWindow:[serializedData objectForKey:@"message"]];
        return [serializedData objectForKey:@"message"];
    }
    return nil;
}



@end
